/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package lamhnhServlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author user
 */
@WebServlet(name="ShowMemberActivity", urlPatterns={"/ShowMemberActivity"})
public class ShowMemberActivity extends HttpServlet {
   
    /** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        int act = Integer.parseInt(request.getParameter("txtact"));
        RequestDispatcher r1 = request.getRequestDispatcher("lamServletHeader.jsp");
        RequestDispatcher r2 = request.getRequestDispatcher("admin/adminFooter.jsp");
        try
        {
            Connection con = helper.ConnectionHelper.GetConnection();
            String sql = "Select * from UsersActivities where ActivityID=?";
            PreparedStatement p = con.prepareStatement(sql);
            p.setInt(1, act);
            ResultSet rs = p.executeQuery();
            out.println("<html><head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8'><link rel='stylesheet' type='text/css' href='css/clientTemplate.css'><title>Member List</title></head><body><center><table id='tableClientTemplate'><tr id='headerClientTemplate' style='background-color: orange'><td>");
            r1.include(request, response);
            out.println("</td></tr><tr id='middleClientTemplate'><td>");
            out.println("<table align='center'>");
            out.println("<tr>");
            out.println("<th>");
            out.println("User Name");
            out.println("</th>");
            out.println("<th>");
            out.println("Payment");
            out.println("</th>");
            out.println("<th>");
            out.println("Submitted");
            out.println("</th>");
            out.println("<th>");
            out.println("Wined");
            out.println("</th>");
            out.println("</tr>");
            while(rs.next())
            {
                out.println("<form action='ActivityManage' method='POST'>");
                out.println("<tr>");
                out.println("<td>");
                out.println("<input type='text' name='txtuser' readonly value='"+rs.getString("UserName")+"'/>");
                out.println("</td>");
                out.println("<td>");
                out.println("<input type='text' name='txtpay' readonly value='"+rs.getString("Payment")+"'/>");
                out.println("</td>");
                out.println("<td>");
                out.println("<input type='text' name='txtsub' readonly value='"+rs.getBoolean("Submitted")+"'/>");
                out.println("</td>");
                out.println("<td>");
                out.println("<input type='text' name='txtwin' readonly value='"+rs.getString("Wined")+"'/>");
                out.println("</td>");
                out.println("<td>");
                out.println("<input type='hidden' name='txtact' readonly value='"+act+"'/>");
                out.println("</td>");
                out.println("<td>");
                out.println("<input type='submit' value='Edit' />");
                out.println("</td>");
                out.println("</tr>");
                out.println("</form>");
            }
                out.println("</table>");
                out.println("</td></tr><tr id='footerClientTemplate'><td>");
                r2.include(request, response);
                out.println("</td></tr></table></center></body></html>");
        }catch(Exception e)
        {
            e.printStackTrace();
        }
    } 

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    } 

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
